const studentModel = require("../model/studentModel")
const userModel = require("../model/userModel")

module.exports = {
    upload(roleType, id, file, user) {
        if (file) {
            user.avatarUrl = `uploads/${file.filename}`
            // console.log("图片更新了", user)
        }
        if (roleType == 3) {
            // 学生
            user.studentname = user.username
            return studentModel.findByIdAndUpdate({ _id: id }, user, { returnDocument: 'after' })
        } else {
            // 管理员或者教师
            return userModel.findByIdAndUpdate({ _id: id }, user, { returnDocument: 'after' }).populate("role")
        }
    }
}